package com.ruikc.study.demo.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruikc.study.demo.util.Constant;
import com.ruikc.study.demo.util.RateLimit;
import com.ruikc.study.demo.util.Result;

@RestController
public class TestController {

    private static final Logger logger = LogManager.getLogger(TestController.class);

    @RateLimit(Constant.DEFAULT)
    @GetMapping("/")
    public Result hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        logger.debug("Debug message"); // 低级别日志（需配置启用）
        logger.info("Info message");
        // logger.error("Error message", new Exception("Test error"));
        return Result.ok(String.format("Hello view to111 / %s!", name));
    }

    @GetMapping("/public/test")
    public Result test(@RequestParam(value = "name", defaultValue = "World") String name) {
        logger.debug("Debug message"); // 低级别日志（需配置启用）
        logger.info("Info message");
        // logger.error("Error message", new Exception("Test error"));
        return Result.ok(String.format("Hello %s!", name));
    }

}
